package com.dz;


import android.content.Intent;

import androidx.fragment.app.Fragment;

import com.dz.pojo.Crime;

public class CrimeListActivity extends SingleFragmentActivity implements CrimeListFragment.Callbacks,CrimeFragment.Callbacks{

    @Override
    protected CrimeListFragment createFragment() {
        return new CrimeListFragment();
    }

    @Override
    protected int getLayoutResId() {
        //使用了别名资源，平板再次生成了单版面布局
        return R.layout.activity_masterdetail;
    }

    @Override
    public void onCrimeSelected(Crime crime) {
        if (findViewById(R.id.detail_fragment_container) == null) {
            Intent intent = CrimePageActivity.newIntent(this, crime.getId());
            startActivity(intent);
        } else {
            Fragment newDetail = CrimeFragment.newInstance(crime.getId());
            getSupportFragmentManager().beginTransaction()
                    .replace(R.id.detail_fragment_container, newDetail)
                    .commit();
        }
    }

        public void onCrimeUpdated(Crime crime){
            CrimeListFragment listFragment = (CrimeListFragment)
                    getSupportFragmentManager()
                            .findFragmentById(R.id.fragment_container);
            listFragment.updateUI();
        }
}
